local skel = fk.CreateSkill {
  name = "emo__diesi",
}

Fk:loadTranslationTable{
  ["emo__diesi"] = "迭思",
  [":emo__diesi"] = "结束阶段，你可以依次将每花色至多一张牌当【出其不意】使用，然后将手牌摸至体力上限。",
  ["#emo__diesi"] = "迭思：将一张牌当【出其不意】使用",
}

skel:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and player.phase == Player.Finish and not player:isNude()
  end,
  on_cost = function (self, event, target, player, data)
    local use = player.room:askToUseVirtualCard(player, {
      name = "unexpectation", skill_name = skel.name, prompt = "#emo__diesi", skip = true,
      card_filter = { n = {1,1}, pattern = "." }
    })
    if use then
      event:setCostData(self, use)
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local suits = {"spade", "heart", "club", "diamond"}
    local use = event:getCostData(self)
    while use ~= nil do
      table.removeOne(suits, use.card:getSuitString())
      room:useCard(use)
      if #suits == 0 or player:isNude() or player.dead then
        break
      end
      local pattern = ".|.|" .. table.concat(suits, ",")
      use = player.room:askToUseVirtualCard(player, {
        name = "unexpectation", skill_name = skel.name, prompt = "#emo__diesi", skip = true,
        card_filter = { n = {1,1}, pattern = pattern }
      })
    end
    if player:isAlive() then
      local x = player.maxHp - player:getHandcardNum()
      if x > 0 then
        player:drawCards(x, skel.name)
      end
    end
  end,
})

return skel
